package com.coderman.infosys.auth.adapter.controller.role;

import com.coderman.infosys.auth.adapter.controller.BaseController;
import com.coderman.infosys.auth.adapter.convert.RoleGroupConverter;
import com.coderman.infosys.auth.adapter.vo.role.RoleGroupVO;
import com.coderman.infosys.auth.domain.bo.role.RoleGroupBO;
import com.coderman.infosys.auth.domain.gataway.UserRoleQueryGataway;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import com.coderman.infosys.plat.auth.common.page.PageBO;
import com.coderman.infosys.plat.auth.common.vo.PageVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
* @Description:控制层
* @Author:
* @CreateTime:2022-01-04 15:27:39
* @version v1.0
*/
@RestController
public class RoleGroupQueryController extends BaseController {
	
	protected Logger logger = LoggerFactory.getLogger(RoleGroupQueryController.class);

	@Autowired
	private UserRoleQueryGataway userRoleQueryGataway;

	/**
	 *
	 * @Description 分页获取角色组信息
	 * @param pageVO
	 * @return PageVO<RoleVO>
	 */
	@RequestMapping(value = "/rolegroup/pagelist")
	public ResultDataDto<PageVO> getPageList(@RequestParam(value = "pageVO", required = true) PageVO pageVO){
		PageBO pageBO = pageVO.convertToBO();
		List<RoleGroupBO> roleGroupBOList = userRoleQueryGataway.getRoleGroupPageList(pageBO);
		return ResultDataDto.success(pageVO.initData(RoleGroupConverter.INSTANCE.boList2voList(roleGroupBOList),pageBO.getTotalRows()));
	}

	/**
	 *
	 * @Description 根据code或者名称搜索角色组信息
	 * @param search
	 * @return List<RoleVO>
	 */
	@RequestMapping(value = "/rolegroup/search")
	public ResultDataDto<List<RoleGroupVO>> search(@RequestParam(value = "search", required = true) String search){
		List<RoleGroupBO> roleGroupBOList = userRoleQueryGataway.searchRoleGroup(search);
		return ResultDataDto.success(RoleGroupConverter.INSTANCE.boList2voList(roleGroupBOList));
	}
}
